﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xcap.Xml;

namespace Xcap
{
    public class XcapClient : XcapProcessor
    {
        public XcapClient(Config _config, Account _account) : base(_config, _account){}

        public void GetServerCapabilities()
        {
            HandleRequest(false, xcapAction.GET, xcapDocument.servCaps);
        }

        public void GetResourceLists()
        {
            HandleRequest(true, xcapAction.GET, xcapDocument.resourceLists);
        }

        public void PutResourceLists(string content)
        {
            HandleRequest(true, xcapAction.PUT, xcapDocument.resourceLists, content);
        }

        /// <summary>
        /// Deletes resource-lists document
        /// NOT TESTED!
        /// </summary>
        public void DeleteResourceLists()
        {
            HandleRequest(true, xcapAction.DELETE, xcapDocument.resourceLists);
        }

        /// <summary>
        /// Add new buddy to specified contact list
        /// </summary>
        /// <param name="listName">Name of destination list</param>
        /// <param name="contact">Contact object</param>
        public void PutResourceListsEntry(string listName, Contact contact)
        {
            //vytvorime priamo tu xml conent
            XcapXmlResourceLists xml = new XcapXmlResourceLists();
            //generujem xml conent na vlozenie
            string content = xml.NewContact(contact);
            //toto tam posielam kvoli generovaniu http uri
            resourceListsEntryList = listName;
            //aj toto
            resourceListsEntryUri = contact.Uri;

            HandleRequest(true, xcapAction.PUT, xcapDocument.resourceListsEntry, content);
        }

        /// <summary>
        /// Get an entry by specified contact object
        /// </summary>
        /// <param name="listName">Get it from this list</param>
        /// <param name="contact">Get this contact</param>
        public void GetResourceListsEntry(string listName, Contact contact)
        {
            resourceListsEntryList = listName;
            resourceListsEntryUri = contact.Uri;
            HandleRequest(true, xcapAction.GET, xcapDocument.resourceListsEntry);
        }

        /// <summary>
        /// Delete an entry by specified contact object
        /// </summary>
        /// <param name="listName">Delete it from this list</param>
        /// <param name="contact">Delete this contact</param>
        public void DeleteResourceListsEntry(string listName, Contact contact)
        {
            resourceListsEntryList = listName;
            resourceListsEntryUri = contact.Uri;
            HandleRequest(true, xcapAction.DELETE, xcapDocument.resourceListsEntry);
        }

        public void GetPresRules()
        {
            HandleRequest(true, xcapAction.GET, xcapDocument.presRules);
        }

        public void GetPresRulesIdentity(string ruleId, Contact contact)
        {
            presRulesRuleId = ruleId;
            presRulesIdentityOne = contact.Uri;
            HandleRequest(true, xcapAction.GET, xcapDocument.presRulesIdentity);
        }

        public void PutPresRulesIdentity(string ruleId, Contact contact)
        {
            XcapXmlPresrules xml = new XcapXmlPresrules();
            string content = xml.NewIdentity(contact).ToString();
            Console.WriteLine(content);
            presRulesRuleId = ruleId;
            presRulesIdentityOne = contact.Uri;
            HandleRequest(true, xcapAction.PUT, xcapDocument.presRulesIdentity, content);
        }

        public void DeletePresRulesIdentity(string ruleId, Contact contact)
        {
            presRulesRuleId = ruleId;
            presRulesIdentityOne = contact.Uri;
            HandleRequest(true, xcapAction.DELETE, xcapDocument.presRulesIdentity);
        }

        /// <summary>
        /// Uploads specified XML pres-rules document
        /// </summary>
        /// <param name="content">XML content to be uploaded</param>
        public void PutPresRules(string content)
        {
            HandleRequest(true, xcapAction.PUT, xcapDocument.presRules, content);
        }

        //dostanem svoje vlastne pidfko
        public void GetPidf()
        {
            //targetUser = account.SipUri;
            HandleRequest(true, xcapAction.GET, xcapDocument.pidf);
        }

        public void GetPidf(string userUri)
        {
            targetUser = userUri;
            HandleRequest(true, xcapAction.GET, xcapDocument.pidf);
        }

        public void PutPidf(string content)
        {
            HandleRequest(true, xcapAction.PUT, xcapDocument.pidf, content);
        }
        
    }
}
